package main
import(
	"fmt"
	"time"
)

func main(){
	now := time.Now()
	fmt.Printf("now=%v typt=%T",now,now)

	// 通过now获取年月日时分秒
	fmt.Printf("年=%v\n", now.Year())
	fmt.Printf("月=%v\n", now.Month())
	fmt.Printf("月=%v\n", int(now.Month()))
	fmt.Printf("日=%v\n", now.Day())
	fmt.Printf("时=%v\n", now.Hour())
	fmt.Printf("分=%v\n", now.Minute())
	fmt.Printf("秒=%v\n", now.Second())
	
	// 格式化时间
	fmt.Printf("当前的年月日 %d-%d-%d %d:%d:%d \n",now.Year(),now.Month(),now.Day(),
	now.Hour(),now.Minute(),now.Second())

	dateStr := fmt.Sprintf("当前的年月日 %d-%d-%d %d:%d:%d \n",now.Year(),now.Month(),now.Day(),
	now.Hour(),now.Minute(),now.Second())

	fmt.Printf("dateStr=%v\n",dateStr)

	// 格式化时间
	fmt.Printf(now.Format("2006-01-02 15:04:05"))
	fmt.Printf(now.Format("2006-01-02"))
	fmt.Printf(now.Format("15:04:05"))
	fmt.Println()

	fmt.Printf("unix时间戳=%v unixnano时间戳=%v \n",now.Unix(),now.UnixNano())


}